/**
 * 树节点
 * 
 * @author shuyuan.dai 2021-03-25
 */
class TreeNode {
    constructor(val) {
        this.val = val;
        this.lchild = null;
        this.rchild = null;
        this.parent = null;
    }

    toString() {
        let stack = [{n: this, d: 0, prefix: ""}], results = [];
        while(stack.length > 0) {
            let tk = stack.pop();
            results.push(`${" ".repeat(tk.d)}${tk.prefix}${tk.n.val}`);
            if(tk.n.rchild != null) {
                stack.push({n: tk.n.rchild, d: tk.d + 1, prefix: "r-"});
            }
            if(tk.n.lchild != null) {
                stack.push({n: tk.n.lchild, d: tk.d + 1, prefix: "l-"});
            }
        }
        return "\n" + results.join("\n");
    }
}

exports.TreeNode = TreeNode;